package com.tjsinfo.tjsoa.worklog.action;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.common.DateTimeFromConver;
import com.tjsinfo.tjsoa.common.TestRiQi;
import com.tjsinfo.tjsoa.system.vo.User;
import com.tjsinfo.tjsoa.worklog.bo.IWorkLogMainBo;
import com.tjsinfo.tjsoa.worklog.vo.WorkLogMain;

public class WorkLogDateModleDownAction extends Action{
	protected IWorkLogMainBo workLogMainBo;

	
	public IWorkLogMainBo getWorkLogMainBo() {
		return workLogMainBo;
	}
	public void setWorkLogMainBo(IWorkLogMainBo workLogMainBo) {
		this.workLogMainBo = workLogMainBo;
	}
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		User user = getUser(request);
		Date date = getDate(request);
		Map<Date, WorkLogMain> map = workLogMainBo.selectWorkLogTypeAndYearMAP("D", 1900+date.getYear(), user.getUser_id());
		request.setAttribute("yueli", date);
		request.setAttribute("worklogmap", map);
		return mapping.findForward("ok");
	}
	protected Date getDate(HttpServletRequest request) {
		String datestr = request.getParameter("date");
		Date date =	DateTimeFromConver.datetostr(datestr);
		date =	TestRiQi.downMonth(date);
		return date;
	}
	protected User getUser(HttpServletRequest request) {
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		return user;
	}

}
